//
//  Team9s_homePicCell.m
//  Team9Project
//
//  Created by dlios on 15/10/19.
//  Copyright © 2015年 apple. All rights reserved.
//

#import "Team9s_homePicCell.h"
#import "Team9s_homePicModel.h"
#import <Masonry.h>
@implementation Team9s_homePicCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self creatAllView];
    }
    return self;
}





- (void)setPicModel:(Team9s_homePicModel *)picModel{
    if (_picModel != picModel) {
        _picModel = picModel;
    }
    
//    [Team9Tool sd_imageView:self.picImageView image:_picModel.pic placeholder:[UIImage imageNamed:@"111"]];
    [Team9Tool sd_imageView:self.picImageView image:nil placeholderImage:@"111" detailImage:_picModel.pic];
    self.describleLabel.text = _picModel.col_remark;
    
    
    [self makeConstraints];
   
}

-(void)creatAllView
{
    
    
    self.contentView.backgroundColor = [UIColor whiteColor];
    
    // pic
    self.picImageView = [[UIImageView alloc] init];
    [self.contentView addSubview:self.picImageView];
    self.picImageView.backgroundColor = [UIColor clearColor];
    self.picImageView.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
    [self.picImageView addGestureRecognizer:tap];

    
    // 描述
    self.describleLabel = [[Team9BaseLabel alloc] init];
    [self.contentView addSubview:self.describleLabel];
    self.describleLabel.numberOfLines = 0;
    [self.describleLabel sizeToFit];
    self.describleLabel.font = [UIFont systemFontOfSize:13 / 667.0 * HEGHT];
    
    
    
}


- (void)tapAction:(UITapGestureRecognizer *)tap{

    self.block();
}




- (void)makeConstraints{
    
    if (self.picModel.pic) {
        
        
        CGFloat a = [self.picModel.pic_height floatValue];
        CGFloat b = [self.picModel.pic_width floatValue];
        CGFloat proportion = a / b;

        [self.picImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView.mas_top).offset(10);
            make.left.equalTo(self.contentView.mas_left).offset(10);
            make.right.equalTo(self.contentView.mas_right).offset(-10);
            make.height.mas_equalTo(self.picImageView.mas_width).multipliedBy(proportion);
            
        }];
    }else{
        [self.picImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView.mas_top).offset(10);
            make.left.equalTo(self.contentView.mas_left).offset(10);
            make.right.equalTo(self.contentView.mas_right).offset(-10);
            make.bottom.equalTo(@0);
        }];

    }
    

    
    
    [self.describleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.picImageView.mas_bottom).offset(10);
        make.left.equalTo(self.contentView.mas_left).offset(10);
        make.right.equalTo(self.contentView.mas_right).offset(-10);

        
    }];
    
        
}


@end
